
import React, { lazy } from 'react';
import DefaultConfig from '../../config.default'
//获取route后缀文件 加载
const files = import.meta.glob<{ router: string }>('./*.route.ts', { eager: true })
let configRoute: any[] = []
const keys = Object.keys(files)
keys.map((filename) => {
  configRoute = [...configRoute, ...files[filename].router]
})
//自动注册pages下的文件默认注册地址为index 都是懒加载
const pages = import.meta.glob<{ router: string }>('../pages/*/index.tsx', { eager: true })
let pagesList: routesConfigItem[] = []
const pagskeys = Object.keys(pages)
pagskeys.map((filename) => {
  const name = filename.split('/')[2]
  pagesList = [...pagesList, {
    path: "/" + name,
    exact: true,
    component: lazy(() => import(`../pages/${name}/index.tsx`)),
    selected: name
  }]
})
export interface routesConfigItem {
  path?: string
  exact?: boolean
  strict?: boolean
  component?: JSX.Element | React.ComponentType<any>
  selected?: string
  children?: routesConfigItem[]
  redirect?: string
  from?: string
  to?: string
}

const routes: routesConfigItem[] = [
  ...configRoute,
  ...pagesList,
  {
    from: "/",
    redirect: DefaultConfig.defaultPage,
    exact: true
  },

];

export default routes